//
//  RBWechatLoginVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/5.
//

#import "RBWechatLoginVC.h"
#import "RBDefine.h"
#import "RBNavigationBar.h"
#import "UIView+RBAdd.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import <Masonry.h>
#import "RBGradientView.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RBLoginRuleView.h"
#import "RBPasswordLoginVC.h"
#import "RBSmsLoginVC.h"
#import <UIControl+YYAdd.h>

@interface RBWechatLoginVC ()

@property(nonatomic, strong)RBGradientView *bgView;
@property(nonatomic, strong)RBNavigationBar *navigationBar;
@property(nonatomic, strong)IBOutlet UIView *topView;
@property(nonatomic, strong)IBOutlet UIView *bottomView;
@property(nonatomic, strong)RBLoginRuleView *ruleView;

@end

@implementation RBWechatLoginVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
}

#pragma mark - Private

- (void)setup
{
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = UIColor.whiteColor;
    self.bgView.hidden = NO;
    self.navigationBar.hidden = NO;
    
    [self.topView zoomSubViewsWithSelf];
    self.topView.height = Zoom(self.topView.height);
    [self.view addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.navigationBar.mas_bottom).offset(Zoom(50));
        make.height.mas_equalTo(self.topView.height);
    }];
    
    [self.bottomView zoomSubViewsWithSelf];
    self.bottomView.height = Zoom(self.bottomView.height);
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(self.ruleView.mas_top).offset(Zoom(-31));
        make.height.mas_equalTo(self.bottomView.height);
    }];
}

#pragma mark - Network

#pragma mark - Event

- (void)backBtnTapped
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)wechatLoginBtnTapped:(id)sender
{
    
}

- (IBAction)passwordLoginBtnTapped:(id)sender
{
    if (self.passwordLoginBlock)
    {
        self.passwordLoginBlock();
    }
}

- (IBAction)smsLoginBtnTapped:(id)sender
{
    if (self.smsLoginBlock)
    {
        self.smsLoginBlock();
    }
}

#pragma mark - Setter

#pragma mark - Getter

- (RBGradientView *)bgView
{
    if (!_bgView)
    {
        self.bgView = ({
            RBGradientView *view = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#CADCFF"], [UIColor colorWithHexString:@"#ffffff"]] locations:@[@0, @1] vertical:YES];
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.mas_equalTo(0);
                make.height.mas_equalTo(595);
            }];
            view;
        });
    }
    return _bgView;
}

- (RBNavigationBar *)navigationBar
{
    if (!_navigationBar)
    {
        self.navigationBar = ({
            RBNavigationBar *bar = RBNavigationBar.new;
            bar.needGradientView = NO;
            [self.view addSubview:bar];
            [bar mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.mas_equalTo(0);
                make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight);
            }];
            [bar.naviBar addBackBtnWithWidth:70 image:[UIImage imageNamed:@"backBlack"]];
            [[bar.naviBar getBackBtn] removeAllTargets];
            [[bar.naviBar getBackBtn] rbAddTapGesWithTarget:self action:@selector(backBtnTapped)];
            bar;
        });
    }
    return _navigationBar;
}

- (RBLoginRuleView *)ruleView
{
    if (!_ruleView)
    {
        self.ruleView = ({
            RBLoginRuleView *view = RBLoginRuleView.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(-MAX(kRBSafeBottomHeight, Zoom(24)));
                make.left.mas_equalTo(Zoom(10));
                make.right.mas_equalTo(-Zoom(10));
            }];
            view;
        });
    }
    return _ruleView;
}

@end
